{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:url('update')}">
        <input type="hidden" name="id" value="{$model.id ?? ''}">
        <input type="hidden" id="imgurl" name="imgurl" value="{$model.activity_pto ?? ''}">

        <!-- 图片地址 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>图片地址：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <img style="width: 100px;height: 100px;" id="src_image" src="{$model.activity_pto ?? ''}" />
                <input type="file" class="input-text" placeholder="图片地址" name="activity_pto" onchange="file_up()">
                <!--onchange="file_up()"-->
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动城市 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动城市：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动城市" name="a_city" value="{$model.a_city ?? ''}" datatype="*" nullmsg="请填写活动城市">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动详细地点 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>详细地点：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="详细地点" name="activity_adress" value="{$model.activity_adress ?? ''}" datatype="*" nullmsg="请填写详细地点">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动标题 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动标题：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动标题" name="title" value="{$model.title ?? ''}" nullmsg="请填写活动标题" datatype="*" />
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动场次 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动场次：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动场次" name="a_top" value="{$model.a_top ?? ''}"  datatype="*" nullmsg="请填写活动场次">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动详情 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动详情：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动详情" name="detail_url" value="{$model.detail_url ?? ''}" datatype="*" nullmsg="请填写活动详情">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 活动链接 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动链接：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动链接" name="url" value="{$model.url ?? ''}" datatype="*" nullmsg="请填写活动链接">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>


        <!-- 活动日期 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>请填写活动日期：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input style="width:220px;" id="datetime_start" type="text" class="input-text" value="{$model.start_time ?? ''}" placeholder="开始活动日期" name="start_time" datatype="*" nullmsg="请填写开启活动日期">
                &nbsp;~&nbsp;
                <input style="width:220px;" id="datetime_end" type="text" class="input-text" value="{$model.activity_deadline ?? ''}" placeholder="结束活动日期" name="activity_deadline" datatype="*" nullmsg="请填写结束活动日期">
            </div>
        </div>

        <!-- 活动编码 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>活动编码：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="活动编码" name="activity_code" value="{$model.activity_code ?? ''}" datatype="*" nullmsg="请填写活动编码">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/layui/layui.js"></script>
<script>

    $(function () {
        // 判断 图片是否存在
        var $iamge = $("input[name='imgurl']").val();
        if($iamge == ""){
            $("#src_image").css("display","none");
        }

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").Validform({
            tiptype: 2,
            ajaxPost: true,
            showAllError: true,
            callback: function (ret){
                ajax_progress(ret);
            }
        });


    })


    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#datetime_start'
            ,type: 'datetime'
        });
    });

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#datetime_end'
            ,type: 'datetime'
        });
    });

    // function ifid(){
    //     if(!($("input[name='id']").val() == "")){
    //         years = $("input[name='a_year']").val();
    //         mouths = $("input[name='a_month']").val();
    //         days = $("input[name='a_day']").val();
    //         times = years + "-" + mouths + "-" + days;
    //         $("#datetimes").val(times);
    //     }
    // }

    // 图片上传
    function file_up(){
        // FormData对象，来发送二进制文件。
        var formdata = new FormData(form);

        $.ajax({
            type: "POST",
            url: '{:url(\'upload\')}',
            data:formdata,
            dataType: "json",
            processData: false,
            contentType: false,
            success: function(data){
                console.log(data);
                $("#imgurl").val(data);
            }
        });
    }
</script>
{/block}
